Skip to content

fix: flush StreamedLogAsync tail when stop() cancels the task#754

Merged
vdusek merged 2 commits into
masterfrom
fix/streamed-log-stop-hang-and-tail-flush
May 26, 2026
Merged

fix: flush StreamedLogAsync tail when stop() cancels the task#754
vdusek merged 2 commits into
masterfrom
fix/streamed-log-stop-hang-and-tail-flush

Conversation

@vdusek
Copy link
Copy Markdown
Contributor

@vdusek vdusek commented Apr 22, 2026

Summary

In StreamedLogAsync (src/apify_client/_streamed_log.py), shutdown is driven by stop() cancelling the streaming task. CancelledError unwinds out of the async for before the trailing _log_buffer_content(include_last_part=True) runs, so whatever sits in the buffer (the tail after the last 8601 marker) is silently discarded.

Wrapping the loop in try/finally guarantees the tail is flushed even on cancel.

A regression test covers the bug.

@vdusek vdusek added adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. labels Apr 22, 2026
@vdusek vdusek self-assigned this Apr 22, 2026
@github-actions github-actions Bot added this to the 139th sprint - Tooling team milestone Apr 22, 2026
@github-actions github-actions Bot added the tested Temporary label used only programatically for some analytics. label Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.74%. Comparing base (c15cb1b) to head (45ba2d2).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #754      +/-   ##
==========================================
+ Coverage   94.72%   94.74%   +0.02%     
==========================================
  Files          48       48              
  Lines        5044     5045       +1     
==========================================
+ Hits         4778     4780       +2     
+ Misses        266      265       -1     
Flag Coverage Δ
integration 93.18% <100.00%> (+0.02%) ⬆️
unit 83.52% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vdusek vdusek force-pushed the fix/streamed-log-stop-hang-and-tail-flush branch from ba41d95 to 5b6a9dd Compare April 22, 2026 09:29
@vdusek vdusek marked this pull request as draft April 27, 2026 07:47
@vdusek vdusek force-pushed the fix/streamed-log-stop-hang-and-tail-flush branch from 5b6a9dd to 8986424 Compare May 25, 2026 14:26
@vdusek vdusek force-pushed the fix/streamed-log-stop-hang-and-tail-flush branch from 8986424 to 4101ef4 Compare May 25, 2026 14:37
@vdusek vdusek changed the title fix: prevent StreamedLog stop() from dropping tail or hanging on silent stream fix: flush StreamedLogAsync tail when stop() cancels the task May 25, 2026
@vdusek vdusek marked this pull request as ready for review May 25, 2026 14:48
@vdusek vdusek requested a review from janbuchar May 25, 2026 14:48
…op-hang-and-tail-flush

# Conflicts:
#	tests/unit/test_logging.py
@vdusek vdusek merged commit ea23338 into master May 26, 2026
25 checks passed
@vdusek vdusek deleted the fix/streamed-log-stop-hang-and-tail-flush branch May 26, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants